<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/10
 * Time: 12:01
 */

namespace plugin\admin\app\logic\image;


use plugin\admin\app\logic\BaseLogic;
use plugin\admin\app\model\font\FontModel;
use plugin\admin\app\model\image\ImageCommandPlanModel;
use support\Request;
use support\Response;

class AiimagecommandLogic extends BaseLogic
{
    protected static $instance;

    public function __construct()
    {
        $this->model = new ImageCommandPlanModel();
    }

    public static function getInstance()
    {
        //        if(is_object(self::$instance)){
//            return self::$instance;
//        }

        return new self();
    }

    public function select(Request $request): Response
    {
        $field = $request->input('field');
        if($field==false){
            $request->inputSet('field','sort');
            $request->inputSet('order','desc');
        }

        $request->inputSet('isdel','0');
        return parent::select($request);
    }

    public function insert(Request $request): Response
    {
        return parent::insert($request);
    }


    public function update(Request $request): Response
    {
        return parent::update($request);
    }

    public function delete(Request $request): Response
    {
        return parent::isDelete($request);
    }

    public function copy(Request $request): Response
    {
        $first = $this->model->find($request->input('id'));
        if($first==false){
            throw new IndexException(4020,'模板不存在');
        }
        $insert = $first->toArray();
        unset($insert['id'],$insert['created_at'],$insert['updated_at']);
        $insert['name'] = $insert['name'].'-复制';
        $insert['status'] = '0';
        $planid = $this->model->insertGetId($insert);

        return $this->json(0);
    }
}